<%--
  Created by IntelliJ IDEA.
  User: 22179
  Date: 2025/3/3
  Time: 19:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <script src="/static/css/jquery-3.3.1.js"></script>
</head>
<body>
    <form action="/Book/addbook" method="post">
        <input value="addbook" name="method" hidden><br>
        书名:<input type="text" name="bookname" id="bookname">
        <span id="uSpan"></span>
        <br>
        作者:<input type="text" name="autho"><br>
        数量:<input type="text" name="bsum"><br>
        价格:<input type="text" name="price"><br>
        <input type="submit"  onclick="dl()" value="提交">
    </form>
    <script>
        //1.为用户名绑定失去焦点事件
        $("#bookname").blur(function (){
            var bookname = $("#bookname").val();
            //2.jQuery的Post方式实现AJAX
            $.post(
                //请求的资源路径
                "/user1",
                //请求参数
                "bookname=" + bookname
                ,

                //回调函数
                function (data) {
                    //将响应的数据显示到span标签
                    if(data == "1"){
                        $("#uSpan").html("图书已存在,不可添加");
                        $("#uSpan").css("color","red");
                    }else{
                        $("#uSpan").html("图书可添加");
                        $("#uSpan").css("color","green");
                    }
                },
                //响应数据形式
                "text"
            );
        });
        function dl() {
            var bookname = $("#bookname").val();
            var autho = $("input[name='autho']").val();
            var bsum = $("input[name='bsum']").val();
            var price = $("input[name='price']").val();
            location.href="/Book/addbook&bookname="+bookname+"&autho="+autho +"&bsum="+bsum+"&price="+price;
        }

    </script>

</body>
</html>
